function counts(){
	$.ajax({
		url:'/user/counts',
		type:'get',
		dataType:'json',
		success:function(res){
			page=Math.ceil(res/10);
		},
		error:function(){
			layer.msg("连接失败")
		}
	})
}
function findAll(page){
	$("#request").empty();
	$.ajax({
		url:'/user/findAll',
		type:'get',
		data:{'page':page},
		dataType:'json',
		success:function(res){
			for (var i = 0; i < res.length; i++) {
				var content='<tr class="gradeX">'
					+'<td>'+res[i].username+'</td>'
			        +'<td>'+res[i].nickname+'</td>'
			        +' <td>'
			        +'<div class="tpl-table-black-operation">'
			        +'<a href="javascript:updaterole('+res[i].userId+');">'
			        +'<i class="am-icon-pencil"></i>更改角色'
			        +'</a>'
			        +'<a href="javascript:;" class="tpl-table-black-operation-del">'
			        +'<i class="am-icon-trash"></i> 删除'
			        +'</a>'
			        +'</div>'
			        +' </td>'
			        +'</tr>';
				$("#request").append($(content));
			}
			
		},
		error:function(){
			layer.msg("连接失败")
		}
	})
}
function updaterole(userid){

	$.ajax({
		url:'/role/findAll',
		type:'get',
		dataType:'json',
		success:function(res){
			var content='<select style="width:200px;position: absolute;left:50%;margin-left:-100px;margin-top:20px" id="role"></select>'
			      +'<div style="text-align: center;margin-top: 70px;"><button type="button" class="am-btn am-btn-primary am-btn-xs" onclick="changerole('+userid+')">确定</button></div>'
			      layer.open({
					  type: 1,
					  title:'解决办法',
					  skin: 'layui-layer-rim', //加上边框
					  area: ['500px', '300px'], //宽高
					  content: content
					});
			for (var i = 0; i < res.length; i++) {
				var content = '<option value="'+res[i].roleId+'">'+res[i].roleName+'</option>'
				$('#role').append($(content));
			}
		},
		error:function(){
			layer.msg("连接失败")
		}
	})
}
function changerole(userid){
	var roleid = $("#role").val();
	$.ajax({
		url:'/role/updaterole',
		type:'get',
		data:{'userid':userid,'roleid':roleid},
		dataType:'json',
		success:function(res){
			if(res.success){
				layer.msg("修改成功");
				layer.closeAll();
				window.location.reload();
			}
		},
		error:function(){
			layer.msg("连接失败")
		}
	})
}